package com.spring.sunflower.common;

import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.spring.sunflower.R;
import com.spring.sunflower.base.BaseActivity;
import com.spring.sunflower.constant.Constant;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Kevin on 2021/7/15<br/>
 * <p>
 * Describe:<br/>
 */
public class FeedbackActivity extends BaseActivity<FeedbackPresenter> implements CommonContract.FeedbackView {
    private EditText etContent, etContract;
    private TextView tvContentNum, tvSubmit;
    private String userID;

    @Override
    public void initView() {
        tvTitle.setText("意见反馈");
        etContent = findViewById(R.id.etContent);
        etContract = findViewById(R.id.etContact);
        tvContentNum = findViewById(R.id.tvContentNum);
        tvSubmit = findViewById(R.id.tvSubmit);
        userID = getField(Constant.KEY_USERID, "");
        etContent.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                tvContentNum.setText(s.toString().length() + "/72");
            }
        });
        tvSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String content = etContent.getText().toString().trim();
                String contact = etContract.getText().toString().trim();
                if (TextUtils.isEmpty(content)) {
                    showToast("请输入您的意见或建议~");
                    return;
                }
                if (TextUtils.isEmpty(contact)) {
                    showToast("请输入您的联系方式");
                    return;
                }
                Map<String, String> map = new HashMap<>();
                map.put("MID", userID);
                map.put("contact", contact);
                map.put("content", content);
                mPresenter.feedbackSubmit(map);
            }
        });
    }

    @Override
    public int getLayoutID() {
        return R.layout.activity_feedback;
    }

    @Override
    public FeedbackPresenter setPresenter() {
        return new FeedbackPresenter(this);
    }

    @Override
    public void feedbackSuccess() {
        showToast("提交成功");
        finish();
    }

    @Override
    public void feedbackFailed() {

    }
}
